//
// Created by francklinson on 2021/10/4 AT 10:18.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    string destCity(vector<vector<string>> &paths) {
        // 寻找出度为0的城市
        unordered_set<string> fromCity;
        for (vector<string> &path: paths) {
            fromCity.insert(path[0]);
        }
        for (auto path: paths) {
            if (!fromCity.count(path[1]))
                return path[1];
        }
        return "";
    }
};

int main() {
    vector<vector<string>> paths{{"London",   "New York"},
                                 {"New York", "Lima"},
                                 {"Lima",     "Sao Paulo"}};
    Solution solution;
    cout << solution.destCity(paths) << endl;
    return 0;
}

